<%
    Users user = Trader.getUser(request.getParameter("uid"));
        wstrader.task.trade.Physical ftask = user.trade.physical;
        wstrader.task.trade.physical.Contract task = user.trade.physical.contract;
        if (!user.Authenticated()) {
                response.sendRedirect("logon.jsp");
                return;
        }
        ((Tasks)ftask.getOwner()).clearFocus();
        ftask.setFocus(true);	
        Trader.window_width = "90%";	
        ResultSet rs;
%>

<%@include file="../header.jsp"%>

<%
        //long focused_id = task.doTask();
        //if (focused_id <= 0) focused_id = 1;
        //Record rc   = task.getRecord("purchase_contract",focused_id);
        float sal_ton =0;
        float pur_ton =0;
        float sal_delvd =0;
        float sal_pend =0;
        float pur_delvd =0;
        float pur_pend =0;
%>

<link href="style.css" rel="stylesheet" type="text/css">

<script language="javascript">
    function doAddNew()
    {
        var form = document.formMain;
        form.new_rec.value = "1";
        form.action = "trade.physical.contract.card.jsp";
        form.submit();
    }

    $(document).ready(function(){
        getTableData();
    });
    
    function getTableData(){
        var cnt_type = $("#cnt_type").val();
        var quality = $("#quality").val();
        var grade = $("#grade").val();
        var buyer_seller = $("#buyer_seller").val();
        var status = $("#status").val();
        var last_date = $("#ls_date").val();
        var uid = $("#uid").val();
        //var table_length = $("#table_length").val();
        var data = "cnt_type=" + cnt_type + "&quality=" + quality + "&grade=" + grade + "&buyer_seller=" + buyer_seller + "&status=" + status + "&last_date=" + last_date + "&uid=" + uid;
        $.ajax({
            type: "GET",
            url: "trade.physical.contract.ajax-source.jsp",
            data: data,
            success: function(msg){
                $("#table_data").html(msg);
            }
        });        
    }

    function doFilter()
    {
        var form = document.formMain;
        form.action = "trade.physical.jsp";
        form.submit();
    }

    function clickCardView()
    {
        var form = document.formMain;
        form.action = "trade.physical.contract.card.jsp";
        form.submit();	
    }

    function cardViewClick(row)
    {
        var form = document.formMain;
        form.contracts.value = row.id;
        dblClick(row);
    }
</script>
<style type="text/css">
    <!--
    .style3 {font-family: Arial}
    .style6 {font-size: 12px}
    .style12 {font-family: Arial; font-size: 12px; }
    -->
</style>
<form action="" method="post" name="formMain" id="formMain">
    <div id="logo">
        <img src="images/contracts.jpg" width="300" height="24">
    </div>
    <fieldset style=" background: #eee; margin-bottom: 20px; margin-top: 20px;">
        <span class="style2 style3" style="font-weight: bold;">Contract Type </span>
        <select id="cnt_type" style="font-size: 11px" onchange="getTableData()">
            <option value="0" selected>All</option>
            <option value="P">PURCHASE</option>
            <option value="S">SALES</option>
            <%task.getResponse().setSelected("cnt_type");%>
        </select>
        <span class="style2 style3" style="font-weight: bold;">Quality </span>
        <select id="quality" style="font-size: 11px" onchange="getTableData()">
            <option value="0" selected>All</option>
            <%
                            task.getResponse().setOption("quality_master","name");
                            task.getResponse().setSelected("quality");
            %>
        </select>
        <span class="style2 style3" style="font-weight: bold;">Grade </span>
        <select id="grade" style="font-size: 11px" onchange="getTableData()">
            <option value="0" selected>All</option>
            <%
                    task.getResponse().setOption(task.getGrade_List());
                    task.getResponse().setSelected("grade");
            %>
        </select>
        <span class="style2 style3" style="font-weight: bold;">Buyer/Seller </span>
        <select id="buyer_seller" style="font-size: 11px" onchange="getTableData()">
            <option value="0" selected>All</option>
            <%
                    task.getResponse().setOption(task.getCtSupplierBuyer());
                    task.getResponse().setSelected("buyer_seller");
            %>
        </select>
        <span class="style2 style3" style="font-weight: bold;">Status </span>
        <select id="status" style="font-size: 11px" onchange="getTableData()">
            <option value ="0" selected>All</option>
            <option value ="F">Fixed</option>
            <option value ="U">Unfixed</option>
            <option value ="D">Delivered</option>
            <option value ="P">Un-delivered</option>			
            <%task.getResponse().setSelected("status");%>
        </select>
        <span class="style2 style3" style="font-weight: bold;">Last Date </span>
        <select id="ls_date" style="font-size: 11px" onchange="getTableData()">
            <%@include file="include/ContractLsDateList.jsp"%>
        </select>
    </fieldset>
    <div id="table_data"></div>

    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td><img src="images/new.gif" width="15" height="15" onClick="doAddNew()"></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" valign="middle">&nbsp;&nbsp;</td>
            <td align="right" valign="middle">&nbsp;</td>
            <td align="right" valign="middle">&nbsp;</td>
            <td align="right" valign="middle"><img src="images/cardview.jpg" width="55" height="18" onClick="clickCardView();">&nbsp;</td>
        </tr>
    </table>
    <input type="hidden" name="uid"        id="uid"       value="<%=user.getuid()%>">
    <input type="hidden" name="task_id"    id = "task_id"   value="0">
    <input name="type" type="hidden" id="type">
    <input name="contracts" type="hidden" id="contracts" value="0">
    <input name="new_rec" type="hidden" id="new_rec" value="0">
</form>
<%@include file="../footer.jsp"%>

